//
//  THJMyOrderDetailVC.m
//  THJXHW
//
//  Created by 河南德艺 on 17/4/8.
//  Copyright © 2017年 河南德艺. All rights reserved.
//

#import "THJMyOrderDetailVC.h"
#import "UIImageView+WebCache.h"
#import "ZBNetworking.h"
#import "THJOrderDetailHeaderCell.h"
#import "THJOrderDetailNormalCell.h"
#import "THJOrderPayDetailVC.h"

@interface THJMyOrderDetailVC ()<UITableViewDelegate,UITableViewDataSource>{
    UITableView * _tableview;
}
@property(nonatomic,strong)NSDictionary * detailInfoDic;
@property(nonatomic,strong)NSArray * dataArr;
@end

@implementation THJMyOrderDetailVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setTableview];
    
    if(KIsiPhoneX){
        [self setXNavBarWithTitle:@"支付详情"];
    }else{
        [self setNavBarWithTitle:@"支付详情"];
    }
    [self getData];
}
-(void)setTableview{
   
    _tableview = [[UITableView alloc] initWithFrame:CGRectMake(0, NavbarHeight, ScreenWidth, ScreenHeight - NavbarHeight) style:UITableViewStylePlain];
    [_tableview registerNib:[UINib nibWithNibName:@"THJOrderDetailHeaderCell" bundle:nil] forCellReuseIdentifier:@"header"];
    [_tableview registerNib:[UINib nibWithNibName:@"THJOrderDetailNormalCell" bundle:nil] forCellReuseIdentifier:@"normal"];
    _tableview.tableFooterView = [[UIView alloc] init];
    _tableview.delegate = self;
    _tableview.dataSource = self;
//    _tableview.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMore)];
    _tableview.showsVerticalScrollIndicator = NO;
//    _tableview.backgroundColor = COLOR(245, 245, 245, 1);
    _tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:_tableview];
    
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArr.count+1;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if(indexPath.row == 0){
        return 325;
    }else{
        return 155;
    }
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if(indexPath.row == 0){
        THJOrderDetailHeaderCell * cell = [tableView dequeueReusableCellWithIdentifier:@"header" forIndexPath:indexPath];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        if(self.detailInfoDic){
            cell.allLab.text = self.detailInfoDic[@"all"];
            cell.yfLab.text = [RSA decryptString:self.detailInfoDic[@"ym"] publicKey:RSA_PubKey];
            cell.wfLab.text = [RSA decryptString:self.detailInfoDic[@"nm"] publicKey:RSA_PubKey];
            cell.kjLab.text = [RSA decryptString:self.detailInfoDic[@"om"] publicKey:RSA_PubKey];
            cell.yjLab.text = [RSA decryptString:self.detailInfoDic[@"am"] publicKey:RSA_PubKey];
        }
        return cell;
    }else{
        THJOrderDetailNormalCell * cell =  [tableView dequeueReusableCellWithIdentifier:@"normal" forIndexPath:indexPath];
        NSDictionary * dic = self.dataArr[indexPath.row - 1];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        [cell setUIWithDic:dic];
        return cell;
    }
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if(indexPath.row != 0){
        [self.navigationController pushViewController:[THJOrderPayDetailVC new] animated:YES];
    }
}
-(void)getData{
    [self SVHUDShow];
    __weak typeof(self) weakself = self;
    NSLog(@"88-itemid:%@",self.itemid);
    NSString *resultStr = [RSA encryptString:self.itemid publicKey:RSA_PubKey];
    NSString * url = @"http://p.thjb.net/thjblink/appdata.php?action=order_info";
    NSDictionary * dic = @{
                           @"id":resultStr,
                           @"type":@"ios"
                           };
    [THJNetWork postNetDataFromUrl:url parameters:dic callback:^(NSDictionary * receiveData, NSError *error) {
        NSString * status = receiveData[@"status"];
        [self SVHUDHiden];
        if([status isEqual:@"fail"]){
            NSLog(@"fail-77777---%@",receiveData);
        }else{
            NSLog(@"success-66666---%@",receiveData);
            weakself.detailInfoDic = receiveData[@"data"];
            weakself.dataArr = receiveData[@"data"][@"list"][@"list"];
            [_tableview reloadData];
        }
    }];
}
-(void)setUIWithDic:(NSDictionary*)dic{
    
}
@end
